package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.qf.mapper.DtsGoodsProductMapper;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.service.DtsGoodsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DtsGoodsProductServiceImpl implements DtsGoodsProductService {
    @Autowired
    DtsGoodsProductMapper productMapper;

    @Override
    public int getTotal() {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getDeleted, false);

        Integer count = productMapper.selectCount(wrapper);
        return count;
    }

    @Override
    public void deleteByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getGoodsId, id);

        productMapper.delete(wrapper);
    }

    @Override
    public void insert(DtsGoodsProduct product) {
        product.setAddTime(new Date());
        product.setUpdateTime(new Date());
        product.setDeleted(false);


        productMapper.insert(product);
    }

    @Override
    public void updateByGoodsId(Integer id) {
        LambdaUpdateWrapper<DtsGoodsProduct> wrapper = new LambdaUpdateWrapper();
        wrapper.eq(DtsGoodsProduct::getGoodsId, id);

        DtsGoodsProduct product = new DtsGoodsProduct();
        product.setDeleted(true);

        productMapper.update( product  , wrapper);
    }
}
